﻿using Quartz;
using Share;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExceptionHandleDemo;

public class MultiStepJob(FirstStep first, SecondStep second) : IJob
{
    public static readonly JobKey Key = JobKey.Create(nameof(MultiStepJob), "group");


    public async Task Execute(IJobExecutionContext context)
    {
        if (context.RefireCount > 10)
        {
            // we might not ever succeed!
            // maybe log a warning, throw another type of error, inform the engineer on call
            return;
        }

        try
        {

            first.Work();

            await Task.Delay(1000);

            second.Work();

        }
        catch (Exception ex)
        {
            // do you want the job to refire?
            throw new JobExecutionException(msg: "", refireImmediately: true, cause: ex);
        }
    }
}
